﻿using SW.Lite.IDAL.Master;
using SW.Lite.Infrastructure.Common;
using SW.Lite.Infrastructure.Service;
using SW.Lite.Model.Master;

namespace SW.Lite.BLL.Master
{
    public class Role
    {
        private static readonly IRole Dal = ServiceLocator.Instance.GetInstance<IRole>("Master.Role");

        /// <summary>
        ///     数据是否存在
        /// </summary>
        /// <param name="id">ID</param>
        public static bool Exists(int id)
        {
            return Dal.Exists(id);
        }

        /// <summary>
        ///     获取单个项
        /// </summary>
        /// <param name="id">ID</param>
        public static RoleModel Single(int id)
        {
            return Dal.Single(id);
        }

        /// <summary>
        ///     获取所有项目
        /// </summary>
        public static PageList<RoleModel> All()
        {
            return Dal.All();
        }

        /// <summary>
        ///     获取所有项目(分页)
        /// </summary>
        public static PageList<RoleModel> All(int pageIndex, int pageSize)
        {
            return Dal.All(pageIndex, pageSize);
        }

        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Insert(RoleModel model)
        {
            return Dal.Insert(model);
        }

        /// <summary>
        ///     更新数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Update(RoleModel model)
        {
            return Dal.Update(model);
        }

        /// <summary>
        ///     删除数据
        /// </summary>
        public static ExecuteResult Delete(params int[] ids)
        {
            return Dal.Delete(ids);
        }

        /// <summary>
        ///     根据AdminID获取角色列表
        /// </summary>
        /// <param name="adminId">AdminID</param>
        public static PageList<RoleModel> GetRolesByAdminId(int adminId)
        {
            return Dal.GetRolesByAdminId(adminId);
        }

        /// <summary>
        ///     根据编码集合获取角色列表
        /// </summary>
        /// <param name="codes">编码集合</param>
        public static PageList<RoleModel> GetRolesByCodes(params string[] codes)
        {
            return Dal.GetRolesByCodes(codes);
        }

        /// <summary>
        ///     添加角色菜单
        /// </summary>
        /// <param name="roleId">角色ID</param>
        /// <param name="menuIds">菜单ID集合</param>
        public static ExecuteResult SaveRoleMenus(int roleId, params int[] menuIds)
        {
            return Dal.SaveRoleMenus(roleId, menuIds);
        }

        /// <summary>
        ///     添加角色按钮
        /// </summary>
        /// <param name="roleId">角色ID</param>
        /// <param name="buttonIds">按钮ID集合</param>
        public static ExecuteResult SaveRoleButtons(int roleId, params int[] buttonIds)
        {
            return Dal.SaveRoleButtons(roleId, buttonIds);
        }
    }
}